from SOAPpy import WSDL
from configuration import Configuration
from client import Client
from util import NoFileFound
import util

print ''
print ' panic@home - C L I E N T'
print ''

# Check for files
files_names = [ 'client.ini']
try:
    util.check_files(files_names)
except NoFileFound, e:
    if e.filename == 'client.ini':
        print '===================================================\n'
        print 'Can not open', e.filename,'. Please, execute setup.\n'
        print '===================================================\n' 
    raise
    
     
    
# Connect with SOAP Server 
wsdlLocation = 'http://panic.c3p0.ger.ufsc.br:8888/soap.php?wsdl'
server = WSDL.Proxy(wsdlLocation)

# authentication
CONFIG_FILENAME = 'client.ini'

conf = Configuration()
conf.load(CONFIG_FILENAME)

client = Client(server, conf)
if client.login() :
    if client.is_working_in_analysis():        
        if client.is_analysis_done():       
            conf = client.take_new_work()
            conf.write(CONFIG_FILENAME) 
    else:
        conf = client.take_new_work()
        conf.write(CONFIG_FILENAME) 

client.send_clientdata()
